﻿// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT License.

using System;
using System.Linq;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using InteractiveDataDisplay.WPF;

namespace LineGraphSample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            var dates = new double[200];
            double[] x = new double[200];
            double[] x2 = new double[200];
            for (int i = 0; i < x.Length; i++)
            {
                x[i] = 3.1415 * i / (x.Length - 1);
                x2[i] = i;
                dates[i] = DateTime.Now.AddDays(i).Ticks;
            }



            for (int i = 0; i < 25; i++)
            {
                var lg = new LineGraph();
                lines.Children.Add(lg);
                lg.Stroke = new SolidColorBrush(Color.FromArgb(255, 0, (byte)(i * 10), 0));
                lg.Description = String.Format("Data series {0}", i + 1);
                lg.StrokeThickness = 2;
                //lg.Plot(x, x.Select(v => Math.Sin(v + i / 10.0)).ToArray());
                //lg.Plot(dates, x.Select(v => Math.Sin(v + i / 10.0)).ToArray());
                lg.Plot(x2, x2);
            }
            // 控制鼠标缩放,与X轴相关

#if LeftRightBound
            plotter.LeftBound = 1;
            plotter.RightBound =2;
            plotter.LeftBound = plotter.RightBound =null;
  
            //plotter.LeftBound = dates[10];
            //plotter.RightBound = dates[100];
#endif
            //plotter.XLabelProvider = new DateLabelProvider();

            btnLeft.Click += BtnLeft_Click;
            btnRight.Click += BtnRight_Click;
            btnRightN.Click += BtnRightN_Click;
            btnLeftN.Click += BtnLeftN_Click;
        }

        private void BtnLeftN_Click(object sender, RoutedEventArgs e)
        {
            //plotter.LeftBound -= 1;
        }

        private void BtnRightN_Click(object sender, RoutedEventArgs e)
        {
            //plotter.RightBound -= 1;
        }

        private void BtnRight_Click(object sender, RoutedEventArgs e)
        {
            //plotter.RightBound += 1;
        }

        private void BtnLeft_Click(object sender, RoutedEventArgs e)
        {
            //plotter.LeftBound += 1;
        }
    }

    public class VisibilityToCheckedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((Visibility)value) == Visibility.Visible;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
        }
    }
}
